﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElingOA6_Admin_DSJCJ.Common;
using System.Data;
using ElingOA6_Admin_DSJCJ.Models;
using DevExpress.Web.Mvc;
using SignalR;
using ElingOA6_Admin_DSJCJ.SignalR;
using System.Runtime.Remoting.Contexts;
using System.Threading;

namespace ElingOA6_Admin_DSJCJ.Controllers
{
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class IndexController : Controller
    {
        //
        // GET: /Index/
        /// <summary>
        /// 人员逻辑类
        /// </summary>
        private BLL.HREmpl HREmplBLL = new BLL.HREmpl();
        private Random Rnd = new Random();
        /// <summary>
        /// 后台首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(string fFunctNo="")
        {

            if (string.IsNullOrEmpty(OperateSession.get(GlobalConstant.PARAM_LOGINID)))
            {
                return Redirect(Url.Action("Index", "Login"));
            }
            else
            {
                
                string sessionId = Session.Contents.SessionID;
                if (!GlobalConstant.SESSION_USER_LIST.ContainsKey(sessionId))
                {
                    GlobalConstant.SESSION_USER_LIST.Add(sessionId, Session[GlobalConstant.PARAM_LOGINID].ToString());
                }

                ViewData["fFunctNo"] = fFunctNo;

#warning 临时代码判断，民主评议结束后删除，包括前台的代码
                //判断是否进行民主评议
                ViewData["scriptString"] = "";
                BLL.PeerReview PeerReviewBLL = new BLL.PeerReview();
                List<Model.PeerReview> PeerReviewModel = PeerReviewBLL.GetList();
                if (PeerReviewModel.Count > 0)
                {
                    if (PeerReviewModel[0].FStatus == "B" && PeerReviewModel[0].FBeginDate < DateTime.Now)
                    {
                        if (PeerReviewModel[0].FEndDate > DateTime.Now)
                        {

                            BLL.PeerReviewVoter PeerReviewVoterBLL = new BLL.PeerReviewVoter();
                            List<Model.PeerReviewVoter> PeerReviewVoterList = PeerReviewVoterBLL.GetModelList(" FPeerReviewID = '" + PeerReviewModel[0].FPeerReviewID + "' and FVoterEmplNo='" + OperateSession.get(Common.GlobalConstant.PARAM_FEMPLNO) + "'");

                            if (PeerReviewVoterList.Count > 0)
                            {

                                if (PeerReviewModel[0].FIsVoteIPControl == "N")
                                {
                                    BLL.PeerReviewResult PeerReviewResultBLL = new BLL.PeerReviewResult();
                                    List<Model.PeerReviewResult> peerReviewResultList = PeerReviewResultBLL.GetModelList(" FVoterEmplNo ='" + OperateSession.get(Common.GlobalConstant.PARAM_FEMPLNO) + "'");
                                    if (peerReviewResultList.Count > 0)
                                    {

                                    }
                                    else
                                    {
                                        ViewData["scriptString"] = "1";
                                    }
                                }

                            }

                        }

                    }

                }
                
                return View();
                
            }
        }

        /// <summary>
        /// 绑定左边树
        /// </summary>
        /// <returns>返回左边树视图</returns>
        public ActionResult Left(string fFunctNo)
        {
            string loginID = OperateSession.get(GlobalConstant.PARAM_LOGINID);
            //#if DEBUG
            //    loginID = "admin";
            //#endif  
            BLL.Index adminIndexBLL = new BLL.Index();

            List<Model.PrvFunctList> prvFunctListList = new List<Model.PrvFunctList>();
            if (loginID == "admin")
            {
                prvFunctListList = adminIndexBLL.GetPrvFunctList();
            }
            else
            {
                prvFunctListList = adminIndexBLL.GetPrvFunctList(loginID);
            }
            string SelectNodeName = "";
            Models.TreeModelList treeModelList = new Models.TreeModelList();
            OperateSession.addList(GlobalConstant.PARAM_PRVFUNCTIONLIST, prvFunctListList);
            if (prvFunctListList.Count > 0)
            {
                List<Model.PrvFunctList> prvFirstList = (from m in prvFunctListList
                                                         where m.FPreFunctNo == "m_PrvFunctList"
                                                         && m.FFunctNo != "m_eAccount"
                                                         orderby m.Fsort
                                                         select m).ToList();
                foreach (Model.PrvFunctList prvModel in prvFirstList)
                {
                    List<Model.PrvFunctList> tmpModelList = (from m in prvFunctListList
                                                             where m.FPreFunctNo == prvModel.FFunctNo
                                                             orderby m.Fsort
                                                             select m).ToList();

                    TreeItemModel treeParentItemModel = new TreeItemModel(null)
                    {
                        //Id = prvModel.FFunctNo,
                        Name = prvModel.FfunctName,
                        ImageUrl = prvModel.FPictName
                    };
                    
                    if (tmpModelList.Count > 0)
                    {
                        treeParentItemModel.Id = prvModel.FFunctNo;
                        if (prvModel.FFunctNo != "m_Town")//镇乡考核·
                        {

                            GetChildFuncList(tmpModelList, treeParentItemModel, prvFunctListList, fFunctNo, ref SelectNodeName);
                        }
                    }
                    else
                    {
                        treeParentItemModel.Id = prvModel.FfunctURL + "|" + prvModel.FFunctNo + "|" + prvModel.FIsNewWindow;
                        if (prvModel.FFunctNo == fFunctNo)
                        {
                            SelectNodeName = treeParentItemModel.Id;
                        }
                        //treeJsonStr += ",'url':'" + Url.Action("Index", prvModel.FFunctURL) + "','target':'content'";
                        //treeJsonStr += ",'attributes':{'url':'" + Url.Action("Index", prvModel.FFunctURL) + "'},'target':'content'";
                    }
                    treeModelList.Add(treeParentItemModel);
                }

            }

            ViewData["SelectNodeName"] = SelectNodeName;
            return View(treeModelList);
        }
        /// <summary>
        /// 页面中部
        /// </summary>
        /// <returns>返回页面中部视图</returns>
        public ActionResult Content()
        {
            //GlobalHost.ConnectionManager.GetHubContext<ElingOA6_Admin_DSJCJ.SignalR.Chat>().Clients.addSomeMessage("admin", "test");
            // ConnectionMapping cc = new ConnectionMapping();
         
           
            return View();
        }
        public void test()
        {

           
            
        }

        void ConnectionMapping_Connected(string obj)
        {
            //string logId = OperateSession.get(GlobalConstant.PARAM_LOGINID);
            //string dd = System.Web.HttpContext.Current.Request.Form[""];

            //System.Web.HttpContext.Current.Request.Cookies.Add(new HttpCookie() {  });
            //IConnection connection = GlobalHost.ConnectionManager.GetConnectionContext<ElingOA6_Admin_DSJCJ.SignalR.ConnectionMapping>().Connection;
            //    return Connection.Broadcast("用户" + logId + "连接");
            //connection.Broadcast("用户" + logId + "连接");


        }


        /// <summary>
        /// 递归获取树形菜单
        /// </summary>
        /// <param name="prvChildList">功能菜单列表</param>
        /// <param name="treeParentItemModel">父级树节点</param>
        /// <param name="prvFunctListList">功能菜单集合</param>
        private void GetChildFuncList(List<Model.PrvFunctList> prvChildList, TreeItemModel treeParentItemModel, List<Model.PrvFunctList> prvFunctListList,string fFunctNo,  ref string SelectNodeName)
        {
            foreach (Model.PrvFunctList prvModel in prvChildList)
            {
                //treeJsonStr += "{'text':'" + prvModel.FFunctName + "','state':'open'";

                List<Model.PrvFunctList> tmpModelList = (from m in prvFunctListList
                                                         where m.FPreFunctNo == prvModel.FFunctNo
                                                         orderby m.Fsort
                                                         select m).ToList();
                if (tmpModelList.Count > 0)
                {
                    //treeJsonStr += ",'children':[";
                    TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                    {
                        Id = prvModel.FFunctNo,
                        Name = prvModel.FfunctName,
                        ImageUrl = prvModel.FPictName
                    };
                    GetChildFuncList(tmpModelList, treeChildItemModel, prvFunctListList,fFunctNo,ref SelectNodeName);
                    //treeJsonStr += "]";
                }
                else
                {
                    //treeJsonStr += ",'url':'" + Url.Action("Index", prvModel.FFunctURL) + "','target':'content'";
                    //treeJsonStr += ",'attributes':{'url':'" + Url.Action("Index", prvModel.FFunctURL) + "','target':'content'}";

                    if (prvModel.FFunctNo == "m_Leave1" || prvModel.FFunctNo == "m_Leave2")
                    {
                        TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                        {
                            Id = prvModel.FfunctURL + "|" + prvModel.FFunctNo+ "|" + prvModel.FIsNewWindow,
                            Name = prvModel.FfunctName,
                            ImageUrl = prvModel.FPictName
                            //Url = DevExpressHelper.GetUrl(new { Controller = prvModel.FFunctURL, Action = "Index" })

                            //Url = Url.Action("Index", prvModel.FFunctURL),
                            //Target = "content"
                        };
                        if (prvModel.FFunctNo == fFunctNo)
                        {
                            SelectNodeName = treeChildItemModel.Id;
                        }
                    }
                    else
                    {
                        TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                        {
                            Id =  prvModel.FfunctURL + "|" + prvModel.FFunctNo+ "|" + prvModel.FIsNewWindow,
                            Name = prvModel.FfunctName,
                            ImageUrl = prvModel.FPictName
                            //Url = DevExpressHelper.GetUrl(new { Controller = prvModel.FFunctURL, Action = "Index" })

                            //Url = Url.Action("Index", prvModel.FFunctURL),
                            //Target = "content"
                        };
                        if (prvModel.FFunctNo == fFunctNo)
                        {
                            SelectNodeName = treeChildItemModel.Id;
                        }
                    }

                }

            }
        }
        /// <summary>
        /// 上部
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult Top()
        {
            string entityNo = GlobalConstant.ENTITYNO;
            ViewData["AMAttendanceTime"] = "";
            ViewData["PMAttendanceTime"] = "";
            string loginID = OperateSession.get(GlobalConstant.PARAM_LOGINID);
            BLL.Attendance attendanceBLL = new BLL.Attendance();
            //考勤查询时间 显示                          
            string today = DateTime.Now.Date.ToString();
            string middleTime = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " " + "12:00";
            //签到显示时间
            DataSet dsAM = attendanceBLL.GetAMAttendanceTimeDS(entityNo, loginID, today);
            if (dsAM.Tables[0].Rows.Count > 0)
            {
                if (DateTime.Parse(middleTime) > DateTime.Parse(DateTime.Parse(dsAM.Tables[0].Rows[0]["FAttendanceTime"].ToString()).ToString("yyyy-MM-dd HH:mm")))
                {
                    ViewData["AMAttendanceTime"] = DateTime.Parse(dsAM.Tables[0].Rows[0]["FAttendanceTime"].ToString()).ToString("HH:mm");
                }
            }
            //签退显示时间
            DataSet dsPM = attendanceBLL.GetPMAttendanceTimeDS(entityNo, loginID, today);

            if (dsPM.Tables[0].Rows.Count > 0)
            {
                if (DateTime.Parse(middleTime) <= DateTime.Parse(DateTime.Parse(dsPM.Tables[0].Rows[0]["FAttendanceTime"].ToString()).ToString("yyyy-MM-dd HH:mm")))
                {
                    ViewData["PMAttendanceTime"] = DateTime.Parse(dsPM.Tables[0].Rows[0]["FAttendanceTime"].ToString()).ToString("HH:mm");
                }
            }
            ViewData["AttendanceIpAddress"] = HREmplBLL.GetAttendanceIpAddress(entityNo, loginID);



            return View();
        }
        /// <summary>
        /// 底部
        /// </summary>
        /// <returns>视图</returns>
        [OutputCache(Duration = 1, VaryByParam = "none")]
        public ActionResult Buttom()
        {
            ViewData["DeptName"] = "";
            ViewData["EmpName"] = "";
            string loginName = OperateSession.get(GlobalConstant.PARAM_USERNAME);
            //获取部门信息
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
            string entityNo = GlobalConstant.ENTITYNO;
            if (emplNo != "" && entityNo != "")
            {
                DataSet ds = HREmplBLL.GetEmplFromViewByEmplNo(emplNo, entityNo);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if (dt.Rows[i]["FIsMainPosition"].ToString() == "Y")
                        {
                            ViewData["EmpName"] = dt.Rows[i]["FEmpName"].ToString();
                            ViewData["DeptName"] = dt.Rows[i]["FDeptName"].ToString();
                            OperateSession.add(GlobalConstant.PARAM_DEPTNO, dt.Rows[i]["FDeptNo"].ToString());
                            break;
                        }

                    }
                }
            }

            //获取组织名称
            //string organizeName =GlobalConstant.or


            //organizeName = "鄞州财政局";

            //string IP = Common.GenerateUtil.GetClientIPv4Address();
            //try
            //{
            //    string HostName = Dns.GetHostName(); //得到主机名
            //    IPHostEntry IpEntry = Dns.GetHostEntry(HostName);
            //    for (int i = 0; i < IpEntry.AddressList.Length; i++)
            //    {
            //        //从IP地址列表中筛选出IPv4类型的IP地址
            //        //AddressFamily.InterNetwork表示此IP为IPv4,
            //        //AddressFamily.InterNetworkV6表示此地址为IPv6类型
            //        if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
            //        {
            //            IP= IpEntry.AddressList[i].ToString();
            //        }
            //    }
            //}
            //catch (Exception)
            //{
            //    IP = "";
            //}
            //if (IP == "")
            //{
            //    IP = IP = Common.GenerateUtil.GetClientIPv4Address(); 
            //}

            //ViewData["IP"] = IP;

            //ViewData["loginName"] = loginName;
            // return View();
            return PartialView();
        }

        /// <summary>
        /// 导航条
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult BoardTop()
        {
            return View();
        }
        /// <summary>
        /// 首页中间检查的过度页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Check()
        {
            return View();
        }
        /// <summary>
        /// 注销
        /// </summary>
        public void Logout()
        {

            OperateSession.del(GlobalConstant.PARAM_USERNAME);
            OperateSession.del(GlobalConstant.PARAM_LOGINID);
            Session.Clear();
            Response.Write("<script>window.top.location.replace('" + Url.Action("Index","Login") + "')</script>");
            Response.Flush();
            Response.End();
        }
        /// <summary>
        /// 退出
        /// </summary>
        public void LogExit()
        {

            OperateSession.del(GlobalConstant.PARAM_USERNAME);
            OperateSession.del(GlobalConstant.PARAM_LOGINID);
            Session.Clear();
            Response.Write("<script>window.top.close()</script>");
            Response.Flush();
            Response.End();
        }



        //
        // GET: /DeskTop/
        private BLL.Entity entityBLL = new BLL.Entity();
        private BLL.Config configBLL = new BLL.Config();
        private BLL.SysPhrase sysPhraseBLL = new BLL.SysPhrase();
        private BLL.ConfigEntry configEntryBLL = new BLL.ConfigEntry();
        private BLL.Common commonBLL = new BLL.Common();
        private BLL.Document documentBLL = new BLL.Document();
        private BLL.HREmpl hrEmplBLL = new BLL.HREmpl();
        private BLL.DocCls docClsBLL = new BLL.DocCls();
        private BLL.DocRecObject docRecObjectBLL = new BLL.DocRecObject();
        private BLL.DocAttach docAttachBLL = new BLL.DocAttach();
        private BLL.LinkType linkTypeBLL = new BLL.LinkType();
        private BLL.LinkTypeEntry linkTypeEntryBLL = new BLL.LinkTypeEntry();
        private BLL.Ad adBLL = new BLL.Ad();
        private BLL.TaxPeriod taxPeriodBLL = new BLL.TaxPeriod();
        private BLL.HRWatchSchedule HRWatchScheduleBLL = new BLL.HRWatchSchedule();
        private bool isLogin = false;
        /// <summary>
        /// 系统参数逻辑类
        /// </summary>
        private BLL.SysParam sysParamBLL = new BLL.SysParam();
        public ActionResult DeskTop()
        {
            //string uid = string.Empty;
            //string message = ssoUidLogin(ref uid);//是否单点登录跳转
            //if (message != string.Empty)
            //{
            //    if (message == "SSOUserBind")
            //    {
            //        return RedirectToAction("SSOUserBind", "Index", new { uid = uid });
            //    }
            //    else if (message == "banLogin")
            //    {
            //        message = "用户禁止登录";
            //    }
            //    else if (message == "loginPast")
            //    {
            //        message = "用户已过期";
            //    }
            //    else if (message == "ipAstrict")
            //    {
            //        message = "ip受限制";
            //    }

            //}

            //ViewData["message"] = message;

            //if (OperateSession.get("messageLogin") != null)
            //{
            //    ViewData["messageLogin"] = OperateSession.get("messageLogin");
            //    OperateSession.add("messageLogin", "");
            //}
            //else
            //{
            //    ViewData["messageLogin"] = "";
            //}

            isLogin = string.IsNullOrEmpty(OperateSession.get(GlobalConstant.PARAM_LOGINID)) ? false : true;
            string entityNo = GlobalConstant.ENTITYNO;
            List<Model.Config> configList = configBLL.GetListAllIsUse(GlobalConstant.ENTITYNO);
            ViewData["configList"] = configList;
            //配置文件明细
            List<Model.ConfigEntry> configEntryList = configEntryBLL.GetModelListWithShowText(GlobalConstant.ENTITYNO, "04");
            ViewData["configEntryList"] = configEntryList;
            List<Model.ConfigEntry> tempEntryList = new List<Model.ConfigEntry>();//存放临时配置文件明细
            Dictionary<string, List<ElingOA6_Admin_DSJCJ.Areas.Admin.Models.DocumentGridModel>> dicDocumentList = new Dictionary<string, List<ElingOA6_Admin_DSJCJ.Areas.Admin.Models.DocumentGridModel>>();
            int total = 0;
            dicDocumentList.Add("doc_tzgg_04", GetDocList("doc_tzgg", "04", 9, out total, "Y"));//通知公告
            total = 0;
            dicDocumentList.Add("doc_swxx_04", GetDocList("doc_swxx", "04", 6, out total, "Y"));//税务信息
            total = 0;
            dicDocumentList.Add("doc_ksdt_04", GetDocList("doc_ksdt", "04", 6, out total, "Y"));//科室动态

            List<ElingOA6_Admin_DSJCJ.Areas.Admin.Models.DocumentGridModel> tpxwList = GetDocList("doc_tpxw", "04", 5, out total, "Y");
            //获取图片新闻的图片路径
            string pic = "";
            string link = "";
            string text = "";
            int picCount = 1;
            string strSelect_btn = "<ul>";
            string strPicshow_img = "<div><dl class='show'></dl>";

            foreach (ElingOA6_Admin_DSJCJ.Areas.Admin.Models.DocumentGridModel docGridModel in tpxwList)
            {
                if (picCount < 6)
                {
                    string thumbSrvFileName = documentBLL.GetDocFThumbSrvFileName(entityNo, docGridModel.FDocId);
                    if (thumbSrvFileName != "")
                    {
                        pic = thumbSrvFileName;
                        link = "/Index/DocView?docId=" + docGridModel.FDocId;
                        if (docGridModel.FTitle.Length > 30)
                        {
                            text = docGridModel.FTitle.Substring(0, 30) + "...";
                        }
                        else
                        {
                            text = docGridModel.FTitle;
                        }


                        //if (picCount == 1)
                        //{
                        //    strSelect_btn += "<li>" + picCount + "</li>";
                        //    strPicshow_img += "<dl class='show'>";
                        //}
                        //else
                        //{
                        //    strSelect_btn += "<li>" + picCount + "</li>";
                        //    strPicshow_img += "<dl>";
                        //}
                        strSelect_btn += "<li>" + picCount + "</li>";
                        strPicshow_img += "<dl><dt><a href='" + link + "' title='' target='_blank'><img src='" + pic + "' alt='" + docGridModel.FTitle + "'></a></dt>";
                        strPicshow_img += "<dd><h2><a href='" + link + "' target='_blank'>" + docGridModel.FTitle + "</a></h2></dd></dl>";
                        picCount++;
                    }

                }
            }
            strSelect_btn += "</ul>";
            strPicshow_img += "</div>";

            if (strPicshow_img != "")
            {
                ViewData["Picshow_img"] = strPicshow_img;
            }
            if (strSelect_btn != "")
            {
                ViewData["Select_btn"] = strSelect_btn;
            }

            if (tpxwList.Count > 0)
            {
                Model.Document firstPicDocumentModel = new Model.Document();
                foreach (ElingOA6_Admin_DSJCJ.Areas.Admin.Models.DocumentGridModel documentModel in tpxwList)
                {
                    if (documentModel.FEditMode == "H")
                    {
                        firstPicDocumentModel = documentBLL.GetModel(documentModel.FDocId);
                        firstPicDocumentModel.FContentTxt = GenerateUtil.NoHTML(firstPicDocumentModel.FContentTxt);

                        break;
                    }
                }
                ViewData["firstPicModel"] = firstPicDocumentModel;
                if (firstPicDocumentModel.FDocId > 0)
                {
                    foreach (ElingOA6_Admin_DSJCJ.Areas.Admin.Models.DocumentGridModel documentModel in tpxwList)
                    {
                        if (documentModel.FDocId == firstPicDocumentModel.FDocId)
                        {
                            tpxwList.Remove(documentModel);
                        }
                        break;
                    }
                }
                else
                {
                    tpxwList.RemoveAt(tpxwList.Count - 1);
                }
            }
            dicDocumentList.Add("doc_tpxw_04", tpxwList);//图片新闻


            //获取类别
            //获取搜索类别
            //List<Model. configList.Where(s=>s.FConfigClass=="05").ToList();
            //{
            //    documentList = Model[key];
            //}
            //List<Model.Config> searchList = configList.Where(s => s.FConfigClass == "05").ToList();


            //DataSet docClsDS = docClsBLL.GetAllSubDocCls(null, entityNo);
            //List<SelectListItem> itemList = new List<SelectListItem>();
            //itemList.Add(new SelectListItem() { Text = "--------选择类别--------", Value = "-1" });
            //for (int i = 0; i < docClsDS.Tables[0].Rows.Count; i++)
            //{
            //    DataRow dr = docClsDS.Tables[0].Rows[i];
            //    int level = 0;
            //    if (dr["level"] != null)
            //    {
            //        level = int.Parse(dr["level"].ToString());
            //        string preString = "";
            //        for (int j = 0; j < level; j++)
            //        {

            //            if (j == 0)
            //            {
            //                preString = System.Web.HttpUtility.HtmlDecode("&nbsp;") + "┗";
            //            }
            //            else
            //            {
            //                preString = System.Web.HttpUtility.HtmlDecode("&nbsp;") + preString;
            //            }

            //        }
            //        dr["FDocClsName"] = preString + dr["FDocClsName"].ToString();
            //        itemList.Add(new SelectListItem() { Text = dr["FDocClsName"].ToString(), Value = dr["FDocClsCd"].ToString() });

            //    }

            //}
            //ViewData["clsList"] = searchList;


            ViewData["DeptName"] = "";
            ViewData["EmpName"] = "";
            if (isLogin)
            {

                string loginName = OperateSession.get(GlobalConstant.PARAM_USERNAME);
                //获取部门信息
                string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
                if (emplNo != "" && entityNo != "")
                {
                    DataSet ds = hrEmplBLL.GetEmplFromViewByEmplNo(emplNo, entityNo);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        DataTable dt = ds.Tables[0];
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (dt.Rows[i]["FIsMainPosition"].ToString() == "Y")
                            {
                                ViewData["EmpName"] = dt.Rows[i]["FEmpName"].ToString();
                                ViewData["DeptName"] = dt.Rows[i]["FDeptName"].ToString();
                                OperateSession.add(GlobalConstant.PARAM_DEPTNO, dt.Rows[i]["FDeptNo"].ToString());
                                break;
                            }

                        }
                    }
                }
            }
            //友情连接
            Dictionary<string, List<Model.LinkTypeEntry>> dicLinkTypeList = new Dictionary<string, List<Model.LinkTypeEntry>>();
            List<Model.LinkType> linkTypeList = linkTypeBLL.GetAllList(entityNo);
            Dictionary<string, string> dicLinkNameList = new Dictionary<string, string>();
            foreach (Model.LinkType linkTypeModel in linkTypeList)
            {
                dicLinkNameList.Add(linkTypeModel.FLinkTypeCD, linkTypeModel.FLinkTypeName);
                dicLinkTypeList.Add(linkTypeModel.FLinkTypeCD, linkTypeEntryBLL.GetListByLinkType(entityNo, linkTypeModel.FLinkTypeCD));
            }
            ViewData["dicLinkTypeList"] = dicLinkTypeList;
            ViewData["dicLinkNameList"] = dicLinkNameList;

            //获取广告信息
            //获取浮动图标
            string strWhere = " FAdProp='1' and FIsUse='1' and FEntityNo='" + GlobalConstant.ENTITYNO + "'";
            ViewData["adFDList"] = adBLL.GetModelList(strWhere);
            //对联广告
            ViewData["adDLList"] = GetDlImage();
            //全屏广告
            strWhere = " (FAdProp='5' or FADProp='2') and FIsUse='1' and FEntityNo='" + GlobalConstant.ENTITYNO + "'";
            ViewData["adQPList"] = adBLL.GetModelList(strWhere);

            //获取专题专栏的数据
            string preDocClsCd = Common.GenerateUtil.GetConfigValue("doc_ztzl_cls");
            Dictionary<string, string> zlOldDic = new Dictionary<string, string>();
            if (preDocClsCd != "")
            {
                zlOldDic = docClsBLL.GetIdAndLogUrl(preDocClsCd, GlobalConstant.ENTITYNO);

            }
            ViewData["zlOldDic"] = zlOldDic;

            return View("DeskTop", dicDocumentList);
        }

        /// <summary>
        /// 显示缩略图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult IndexImage(string pt)
        {
            if (!string.IsNullOrEmpty(pt))
            {


                string strNewImgPath = Url.Content(pt);

                if (GenerateUtil.ExistsFile(strNewImgPath))//图片存在
                {
                    int width = 300;
                    int height = 300;
                    byte[] imgs = OperateImg.breviaryImg(width, height, strNewImgPath, 0);

                    Response.AppendHeader("Content-Length", imgs.Length.ToString());

                    //Response.Clear();
                    Response.ContentType = "image/jpeg";
                    Response.BinaryWrite(imgs);
                    Response.End();
                }
                else
                {
                    return View();
                }
            }
            else
            {
                return View();
            }
            return View();

        }



        /// <summary>
        /// 列表页
        /// </summary>
        /// <param name="keyName"></param>
        /// <param name="configClass"></param>
        /// <param name="pageSize"></param>
        /// <param name="total"></param>
        /// <param name="isHomePage">是否首页</param>
        /// <param name="pageIndex"></param>
        /// <param name="docClsCd"></param>
        /// <returns></returns>
        private List<ElingOA6_Admin_DSJCJ.Areas.Admin.Models.DocumentGridModel> GetDocList(string keyName, string configClass, int pageSize, out int total, string isHomePage, int pageIndex = 1, string docClsCd = "")
        {
            total = 0;
            List<ElingOA6_Admin_DSJCJ.Areas.Admin.Models.DocumentGridModel> documentList = new List<ElingOA6_Admin_DSJCJ.Areas.Admin.Models.DocumentGridModel>();
            Model.Config configModel = configBLL.GetModel(keyName, configClass, GlobalConstant.ENTITYNO);
            string empNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
            if (configModel != null)
            {
                if (configModel.FIsWithDocCls == "Y")
                {
                    //公共条件
                    // FIsShowHomePage = 'Y' and FRecycle='N' FIsEnroll = 'Y'
                    //if (model.FIsHomePageShowLimit == "Y")
                    //{
                    //strWhere.Append(" AND DATEDIFF(DAY, CONVERT(VARCHAR(10), FValidDate, 120), CONVERT(VARCHAR(10), GETDATE(), 120)) <= 0 ");
                    //}
                    string fieldOrder = " FIsTop DESC,FTopSeq ASC,FPubDate";
                    if (isLogin)
                    {
                        //已登录
                        //栏目: 1、不控制查看权限 或者 2、控制查看权限，公开标题 或者 3、控制查看权限，不公开标题，有权限
                        string strWhere = "";
                        string fiedls = "*";
                        string tableName = "";
                        if (docClsCd == "")
                        {
                            if (isHomePage == "Y")
                            {
                                tableName = "dbo.fn_GetIndexDocumentALLByCTE_Login('" + GlobalConstant.ENTITYNO + "','" + keyName + "','" + configClass + "','" + empNo + "')";
                            }
                            else
                            {
                                tableName = "dbo.fn_GetListDocumentALLByCTE_Login('" + GlobalConstant.ENTITYNO + "','" + keyName + "','" + configClass + "','" + empNo + "')";

                            }
                        }
                        else
                        {
                            if (isHomePage == "Y")
                            {
                                tableName = "dbo.fn_GetIndexDocument_DocClsCd_ByCTE_Login('" + GlobalConstant.ENTITYNO + "','" + keyName + "','" + configClass + "','" + empNo + "','" + docClsCd + "')";
                            }
                            else
                            {
                                tableName = "dbo.fn_GetListDocument_DocClsCd_ByCTE_Login('" + GlobalConstant.ENTITYNO + "','" + keyName + "','" + configClass + "','" + empNo + "','" + docClsCd + "')";

                            }
                        }
                        DataSet ds = commonBLL.GetListByPage(tableName, fiedls, pageSize, pageIndex, strWhere, fieldOrder, 1, out total);
                        documentList = ViewDataRowToModel.DataTableToListDocuemt(ds.Tables[0]);
                    }
                    else
                    {
                        //未登录
                        //栏目：1、不控制查看权限 或者 2、控制查看权限，公开标题
                        string strWhere = "";
                        string fiedls = "*";
                        string tableName = "";
                        if (docClsCd == "")
                        {
                            if (isHomePage == "Y")
                            {
                                tableName = "dbo.fn_GetIndexDocumentALLByCTE_NotLogin('" + GlobalConstant.ENTITYNO + "','" + keyName + "','" + configClass + "')";
                            }
                            else
                            {
                                tableName = "dbo.fn_GetListDocumentALLByCTE_NotLogin('" + GlobalConstant.ENTITYNO + "','" + keyName + "','" + configClass + "')";

                            }
                        }
                        else
                        {
                            if (isHomePage == "Y")
                            {
                                tableName = "dbo.fn_GetIndexDocument_DocClsCd_ByCTE_NotLogin('" + GlobalConstant.ENTITYNO + "','" + keyName + "','" + configClass + "','" + docClsCd + "')";
                            }
                            else
                            {
                                tableName = "dbo.fn_GetListDocument_DocClsCd_ByCTE_NotLogin('" + GlobalConstant.ENTITYNO + "','" + keyName + "','" + configClass + "','" + docClsCd + "')";

                            }
                        }
                        DataSet ds = commonBLL.GetListByPage(tableName, fiedls, pageSize, pageIndex, strWhere, fieldOrder, 1, out total);
                        documentList = ViewDataRowToModel.DataTableToListDocuemt(ds.Tables[0]);

                    }
                }
            }



            return documentList;
        }

        /// <summary>
        /// 获取大屏广告图片
        /// </summary>
        /// <returns></returns>
        private List<Model.Ad> GetDlImage()
        {
            //string strEntityNo = ViewState["EntityNo"].ToString();
            //string dummyPath = GenerateUtil.GetConfigValue("dummyPath");
            string defpath = "/Content/images/nothing.jpg";
            List<Model.Ad> adList = new List<Model.Ad>();
            Model.Ad adModel = new Model.Ad();

            List<Model.Ad> adLeftList = new List<Model.Ad>();
            List<Model.Ad> adRightList = new List<Model.Ad>();
            string strWhere = "  FAdProp='3' and FIsUse='1' and FEntityNo='" + GlobalConstant.ENTITYNO + "'";//左对联广告
            adLeftList = adBLL.GetModelList(1, strWhere, "FAdcd desc");
            string strWhere1 = " FAdProp='4' and FIsUse='1' and FEntityNo='" + GlobalConstant.ENTITYNO + "'";//右对联广告
            adRightList = adBLL.GetModelList(1, strWhere1, "FAdcd desc");
            adModel.rightImageUrl = defpath;
            adModel.leftImageUrl = defpath;
            if (!(adLeftList.Count > 0 && adRightList.Count > 0))//如果左右有一个不存在，则不显示对联广告
            {
                return adList;
            }
            Model.Ad adObject = new Model.Ad();

            adObject = adLeftList[0];
            int imgWidth = null == adObject.FAdWidth ? 0 : adObject.FAdWidth.Value;
            int imgHeight = null == adObject.FAdHeight ? 0 : adObject.FAdHeight.Value;
            adModel.leftImageUrl = adObject.FSvrFileName == "" ? defpath : adObject.FSvrFileName;
            adModel.leftWidth = imgWidth;
            adModel.leftHeight = imgHeight;
            adModel.leftHRef = adObject.FAdUrl;
            if (adObject.FAdUrl.Trim() != "javascript:;")
            {
                adModel.leftTarget = "_blank";
            }
            adObject = adRightList[0];
            int imgWidth1 = null == adObject.FAdWidth ? 0 : adObject.FAdWidth.Value;
            int imgHeight1 = null == adObject.FAdHeight ? 0 : adObject.FAdHeight.Value;
            adModel.rightImageUrl = adObject.FSvrFileName == "" ? defpath : adObject.FSvrFileName;
            adModel.rightWidth = imgWidth1;
            adModel.rightHeight = imgHeight1;
            adModel.rightHRef = adObject.FAdUrl;
            if (adObject.FAdUrl.Trim() != "javascript:;")
            {
                adModel.rightTarget = "_blank";
            }

            adModel.hidCouPleZt = "1";
            ViewData["hidCouPleZt"] = adModel.hidCouPleZt;
            adList.Add(adModel);
            return adList;
        }

        public ActionResult AttachDownLoad(decimal attachID)
        {
            //BLL.docAttach attachBll = new BLL.docAttach();
            List<string> list = docAttachBLL.GetSvrFileNameAndOldName(attachID);
            if (list.Count == 2)
            {
                string filePath = Server.MapPath(list[0]);

                return new Common.FileResult() { FilePaht = filePath, FileName = list[1] };

            }
            else
            {
                Response.Write("<script>alert('附件不存在');window.close();</script>");
                Response.Flush();
                Response.End();
                return null;
            }


        }




    }
}
